/******************************************************************************
*
* This file is part of FreeTrack (http://code.google.com/p/qtfreetrack).
* BY Willy Gardiol (willy@gardiol.org)
*
* FreeTrack is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FreeTrack is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar.  If not, see <http://www.gnu.org/licenses/>
*
******************************************************************************/

#ifndef FILENAVIGATOR_H
#define FILENAVIGATOR_H

#include <QtGui>
#include "rotatingdialog.h"

class FTPushButtonIcon;
class FTLabel;
class FTList;
class FTLineEdit;

class FileBrowser : public RotatingDialog
{
    Q_OBJECT
public:
    enum mode { loadMode, saveMode };

private:
    // Private constructor to prevent useage outside static members.
    explicit FileBrowser(FileBrowser::mode m,
                         const QString& title,
                         const QString& default_path,
                         const QStringList& filters,
                         QDir::Filters dir_filter );

public:    // STATIC SECTION
    static QString browseFilename(FileBrowser::mode,
                                  const QString&,
                                  const QString& = "",
                                  const QStringList& = QStringList(),
                                  QDir::Filters dir_filter = QDir::AllEntries | QDir::AllDirs);

private slots:
    // Click on an item in the view
    void itemSelected(QString);
    // Go up...
    void directoryUp();
    // Verify that filename is not duplicated/overwrite
    void checkFilename();

private:
    // Return currently selected filename
    QString getFilename();

    // All the widgets of the dialog box
    FTList* items_list;
    FTPushButtonIcon* directoryUp_button;
    FTPushButtonIcon* select_button;
    FTPushButtonIcon* cancel_button;
    FTLineEdit* filename_edit;
    FTLabel* folder_label;
    FTLabel* caption_label;

    // The directory data
    QDir path;

    // If true, we are in "open" mode, otherwise we are in "save" mode
    FileBrowser::mode _mode;

    QLayout* createHorizontal();
    QLayout* createVertical();

    void populateList();

};

#endif // FILENAVIGATOR_H
